package com.test22_日期时间;

import org.junit.Test;

import java.util.Date;

/**
 * Date，日期类
 */
public class Demo01_Date {

    @Test
    public void test1() {
        // 获取当前日期时间
        Date now = new Date();
        System.out.println(now);
        System.out.println("【当前日期时间戳】" + now.getTime());
    }

    @Test
    public void test2() {
        long datetime = System.currentTimeMillis() - 10000;
        Date dateA = new Date(datetime);    // long转为Date类型
        Date dateB = new Date();
        System.out.println(dateA);
        System.out.println(dateB);
        System.out.println("【两个日期的毫秒数之差】" + (dateB.getTime() - dateA.getTime()));

        System.out.println("【先后关系】AFTER：" + (dateA.after(dateB)));
        System.out.println("【先后关系】BEFORE：" + (dateA.before(dateB)));
    }
}
